var xmlHttpRequest;
function usernameIsExist() {
    var username = document.getElementById('username').value;
    xmlHttpRequest = new XMLHttpRequest();
    xmlHttpRequest.onreadystatechange = processResponse;
    xmlHttpRequest.open("GET","usernameIsExistServlet?username=" + username,true);
    xmlHttpRequest.send(null);
}

function processResponse() {
    if (xmlHttpRequest.readyState === 4) {
        if (xmlHttpRequest.status === 200) {
            var responseInfo = xmlHttpRequest.responseText;
                // .getElementsByTagName("msg")[0].firstChild.data;
            // var span1 = document.getElementById("usernameMsg");
            // if(responseInfo === 'Exist'){
            //     span1.innerText = "INVALID";
            // }else{
            //     span1.innerText = "AVAILABLE";
            // }
            var div1 = document.getElementById('usernameMsg');

            if (responseInfo == "Exist") {
                div1.innerHTML = "<font color='red'>用户名已存在</font>";
            } else {
                div1.innerHTML = "<font color='green'>用户名可用</font>";
            }
        }
    }
}
